#from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from models import api
import os

class MainPageHandler(webapp.RequestHandler):  
    def get(self, action=None):
        if action[0]=="/":
            action=action[1:]
        if action and action[0]=="_":
            self.error(404)
        elif action:
            try:
                action_method=getattr(self, action)
            except AttributeError:
                self.error(404)
            else:
                action_method()
        else:
            self.redirect("/index")

    def post(self, action=None):
        if action[0]=="_":
            self.error(404)
        elif action:
            try:
                action_method=getattr(self, "_handle_action")
            except AttributeError:
                self.error(404)
            else:
                action_method(self.request)
        else:
            self.redirect("/index")

    def index(self):
        path=os.path.join(os.path.dirname(__file__), 'views/mainpage/index.html')
        self.response.out.write(template.render(path, None))
    
    
application = webapp.WSGIApplication([                                   
                                      ('(.*)', MainPageHandler)
                                     ],
                                     debug=True)

def main():
    run_wsgi_app(application)


if __name__ == "__main__":
    main()
